package com.lagou.sqlSession;

import com.lagou.config.XmlConfigBuilder;
import com.lagou.pojo.Configuration;
import org.dom4j.DocumentException;

import java.beans.PropertyVetoException;
import java.io.InputStream;

public class SqlSessionFactoryBuilder {
    public SqlSessionFactory build(InputStream in) throws DocumentException, PropertyVetoException {
        // 第一：将解析出来的内容封装到configuration中
        XmlConfigBuilder configBuilder = new XmlConfigBuilder();
        Configuration configuration = configBuilder.parseConfig(in);

        // 第二：创建SqlSessionFactory对象: 工厂类，生产SqlSession会话对象
        SqlSessionFactory sqlSessionFactory = new DefaultSqlSessionFactory(configuration);
        return sqlSessionFactory;
    }
}
